package net.yc.web.imalachat.push.bean.db;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.time.LocalDateTime;

/**
 * @author: lyc
 * @data: 2021-12-19  16:22
 * @Description: 申请记录表
 */
@Entity
@Table(name = "TB_APPLY")
public class Apply {

    public static final int TYPE_ADD_USER = 1;  // 添加好友
    public static final int TYPE_ADD_GROUP = 2; // 申请加入群

    @Id
    @PrimaryKeyJoinColumn
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(updatable = false, nullable = false)
    private String id;

    /**
     * 描述部分：对我们的申请信息做描述
     * eg：我想加你为好友
     */
    @Column(nullable = false)
    private String description;

    /**
     * 附件 可以为空
     * 可以携带图片地址或者是其他
     */
    @Column(columnDefinition = "TEXT")
    private String attach;

    /**
     * 当前申请类型
     */
    @Column(nullable = false)
    private int type;

    /**
     * 目标id，不进行强关联，不建立主外键关系
     * type ——> TYPE_ADD_USER: User.id
     * type ——> TYPE_ADD_GROUP: Group.id
     */
    @Column(nullable = false)
    private String targetId;

    /**
     * 申请人 可以为空 因为可能是系统管理人员
     * 一个人可以发送很多个申请
     */
    @ManyToOne
    @JoinColumn(name = "applicationId")
    private User application;
    @Column(updatable = false, insertable = false)
    private String applicationId;

    @CreationTimestamp
    @Column(nullable = false)
    private LocalDateTime createAt = LocalDateTime.now();

    @UpdateTimestamp
    @Column(nullable = false)
    private LocalDateTime updateAt = LocalDateTime.now();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getTargetId() {
        return targetId;
    }

    public void setTargetId(String targetId) {
        this.targetId = targetId;
    }

    public User getApplication() {
        return application;
    }

    public void setApplication(User application) {
        this.application = application;
    }

    public String getApplicationId() {
        return applicationId;
    }

    public void setApplicationId(String applicationId) {
        this.applicationId = applicationId;
    }

    public LocalDateTime getCreateAt() {
        return createAt;
    }

    public void setCreateAt(LocalDateTime createAt) {
        this.createAt = createAt;
    }

    public LocalDateTime getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(LocalDateTime updateAt) {
        this.updateAt = updateAt;
    }

    @Override
    public String toString() {
        return "Apply{" +
                "id='" + id + '\'' +
                ", description='" + description + '\'' +
                ", attach='" + attach + '\'' +
                ", type=" + type +
                ", targetId='" + targetId + '\'' +
                ", application=" + application +
                ", applicationId='" + applicationId + '\'' +
                ", createAt=" + createAt +
                ", updateAt=" + updateAt +
                '}';
    }
}
